﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Transport;
using System.Security.Cryptography;
using System.Text;
namespace Transport
{
    public partial class login : System.Web.UI.Page
    {
        NguoiDungControl user;
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected bool doLogin(string username,string password)
        {
            user = new NguoiDungControl();
            //MD5 md5hash = MD5.Create();
            //string pass = GetMd5Hash(md5hash, password);
            bool isTrue = user.checkLogin(username, password);
            return isTrue;
        }
        protected string GetLoaiNguoiDung(string userName)
        {
            try
            {
                NguoiDungControl nguoiDung = new NguoiDungControl();
                nguoi_dung user = nguoiDung.findByUsername(userName);

                if (user != null)
                    return user.loai_nguoi_dung;
                else
                    return null;
            }
            catch (Exception)
            {
                return null;
            }
        }
        static string GetMd5Hash(MD5 md5Hash, string input)
        {

            // Convert the input string to a byte array and compute the hash.
            byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));

            // Create a new Stringbuilder to collect the bytes
            // and create a string.
            StringBuilder sBuilder = new StringBuilder();

            // Loop through each byte of the hashed data 
            // and format each one as a hexadecimal string.
            for (int i = 0; i < data.Length; i++)
            {
                sBuilder.Append(data[i].ToString("x2"));
            }

            // Return the hexadecimal string.
            return sBuilder.ToString();
        }
    }
}